<template>
  <div class="app-container home">
    <el-row :gutter="20">
      <el-col :sm="24" :lg="24">


        <hr/>
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :sm="24" :lg="12" style="padding-left: 20px">
        <h2>个人后台管理框架</h2>


      </el-col>

      <el-col :sm="24" :lg="12" style="padding-left: 50px">
        <el-row>
          <el-col :span="12">
            <h2>技术选型</h2>
          </el-col>
        </el-row>
        <el-row>


        </el-row>
      </el-col>
    </el-row>
    <el-divider/>
    <el-row :gutter="20">
      <el-col :xs="24" :sm="24" :md="12" :lg="8">
        <el-card class="update-log">
          <div slot="header" class="clearfix">
            <span>当月消费饼图</span>
          </div>
          <div class="body">
            <div id="eating" style="height: 350px">

            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="24" :md="12" :lg="8">
        <el-card class="update-log">
          <div slot="header" class="clearfix">
            <span>当月消费折线图</span>
          </div>
          <el-collapse accordion>

          </el-collapse>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="24" :md="12" :lg="8">
        <el-card class="update-log">
          <div slot="header" class="clearfix">
            <span>捐赠支持</span>
          </div>
          <div class="body">

          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {listUserCost} from "@/api/system/cost";

export default {
  name: "Index",
  data() {
    return {
      // 版本号
      version: "3.8.7",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 1000,
        userName: undefined,
        phonenumber: undefined,
        status: undefined,
        deptId: undefined
      },
      // 总条数
      total: 0,
      pieData: [],
      allCount: 0,
    };
  },
  watch: {},
  created() {
    this.getPieData()
    // this.drawPie()
  },
  mounted() {
    // this.getPieData()

  },
  methods: {
    goTarget(href) {
      window.open(href, "_blank");
    },
    async getPieData() {
      await listUserCost(this.queryParams).then(response => {
          try {
            if (response.rows.length > 0) {
              console.log(response, '===')
              let obj_b = {}, obj_l = {}, obj_d = {}, num_b = 0, num_l = 0, num_d = 0;
              for (const resKey in response.rows) {
                num_b += response.rows[resKey].userBreakfast
                num_l += response.rows[resKey].userLunch
                num_d += response.rows[resKey].userDinner
              }
              obj_b["name"] = "早餐" //user_breakfast
              obj_b["value"] = num_b.toFixed(2)
              obj_l["name"] = "午餐" //user_lunch
              obj_l["value"] = num_l.toFixed(2)
              obj_d["name"] = "晚餐" //user_dinner
              obj_d["value"] = num_d.toFixed(2)
              // obj_l["user_lunch"] = num_l
              // obj_d["user_dinner"] = num_d
              this.pieData.push(obj_b, obj_l, obj_d)
              this.allCount = (num_b +num_l + num_d).toFixed(2)
              this.drawPie()
            }
          } catch (e) {
            console.log(e)
          }
          // this.pieData = response.rows;
          // console.log(this.pieData, '===')
        }
      );
    },
    drawPie() {
      var chartDom = document.getElementById('eating');
      var myChart = this.echarts.init(chartDom);
      var option;

      option = {
        title: {
          text: '消费统计',
          // subtext: '本月',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          left: 'left'
        },
        graphic: [
          {
            //环形图中间添加文字
            type: "text", //通过不同top值可以设置上下显示
            left: "center",
            top: "center",
            style: {
              text: `共计\n ${this.allCount}元 `,
              textAlign: "center",
              fill: "#1E7CE8", //文字的颜色
              fontSize: 20,
              lineHeight: 20,
            },
          },
        ],
        series: [
          {
            name: 'Access From',
            type: 'pie',
            radius: ['40%', '70%'],
            data: this.pieData,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };

      option && myChart.setOption(option);
    }
  }
};
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }

  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }

  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>

